<?php

// 删除活动
// DELETE activity.admin.delete

namespace app\api\resource\activity\admin;
use think\Db;

class Delete
{
    // 方法
    public $_method = ['DELETE'];
    // 前置
    public $_pre    = ['adminLogin'];
    // 描述
    public $_description = '删除活动';
    // 参数
    public $_param  = [
        'id' => '活动主键',
    ];
    // 返回
    public $_return = [
        204 => '删除成功',
        500 => '服务器异常',
    ];

    public function run(&$request)
    {
        $id  = $request->delete('id/d',0);

        if (0 == $id) return [422,'活动主键'];

        // 启动事务
        Db::startTrans();
        try{
            Db::name('activity')->where('id',$id)->delete();
            Db::name('activity_signup')->where('activity_id',$id)->delete();

            // 提交事务
            Db::commit();

            return [204,''];  
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            return 500;
        }
    }
}